package com.example.mymatch.controller;


import com.example.mymatch.model.Menu;
import com.example.mymatch.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制类的实现
 * 编写者：吴茂景
 */
@Api(tags = "菜单")
@RestController
public class MenuController {

    @Autowired
    private IMenuService menuService;//对某个业务服务的内容进行定义规范  编写者：吴茂景

    @ApiOperation(value = "查询所有菜单信息",notes = "获取用户信息返回json字符串")
    @RequestMapping("/getStr5")
    public String getMenu(){
        return "My menu";
    }
    @CrossOrigin
    @ApiOperation(value = "对菜单信息的添加方法")
    @GetMapping("/addMenu")
    public int addMenu(Menu menu){
        System.out.println("进入添加菜单信息接口");
        return menuService.insertMenu(menu);
    }

    @GetMapping("getAll5")
    @ApiOperation(value = "对菜单信息的查询方法")
    public List<Menu> getAllUser(Menu menu){
        System.out.println("进入查询方法");

        List<Menu> listMenu=menuService.getAllMenu(menu);

        return listMenu;
    }

    @PutMapping("/editMenu")
    @ApiOperation(value = "对菜单信息的修改方法")
    public int EditUser(@RequestBody Menu menu){
        System.out.println("进入菜单修改方法");
        return menuService.updateMenu(menu);
    }

    @GetMapping("/delMenu")
    @ApiOperation(value = "对菜单信息的删除方法")
    public int Delete(int id){
        System.out.println("进入菜单删除方法");
        int returnValue=0;
        if (id!=0){
            Menu menu=new Menu();
            menu.setId(id);
            returnValue= menuService.deleteMenu(menu);
        }
        return returnValue;
    }

    @GetMapping("/getOne5")
    @ApiOperation(value = "对单条菜单信息的查询方法")
    public  Menu getMenu(int id){
        Menu menu=new Menu();
        System.out.println("进入单条查询方法");
        if (id!=0){
            Menu menu1=new Menu();
            menu1.setId(id);
            menu=menuService.getMenu(menu1);
            System.out.println("返回的数据集合为："+menu.getMenuName());
        }
        return menu;
    }
}
